var SERVER_URL='https://xn--80acdfharf4eieg.xn--p1ai';
$(function(){
$('head').append('');
if($('#online').length==0){
$('body').append('
Статус оператора
');
}
$('').appendTo('body').click(function(){$(this).hide()});
$(''+
'
'+
'
'+
'
'+
'
'+
'
')
.appendTo('body');
$("#messager .bg_bottom a").click(function(){
cnst.openConsultant();
cnst.closeAlert();
return false;
});
if(!cnst.asid){
cnst.pingConsultant();
}else{
if(window.opener && window.opener.location){
$('a').click(cnst.eventClick);
$('body').mousedown(cnst.eventMouseDown).mouseup(cnst.eventMouseUp).mousemove(cnst.eventMouseMove);
}
}
// if(window.opener && window.opener.location){
////, alert(window.opener.location)
// cnst.opener=window.opener.location;
//
// }
});
function getCookie(name) {
var cookie = " " + document.cookie;
var search = " " + name + "=";
var setStr = null;
var offset = 0;
var end = 0;
if (cookie.length > 0) {
offset = cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = cookie.indexOf(";", offset)
if (end == -1) {
end = cookie.length;
}
setStr = unescape(cookie.substring(offset, end));
}
}
return(setStr);
}
function setCookie (name, value, expires, path, domain, secure) {
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
var cnst={
time:0,
timer:5000,
sid:"%PHPSESSID%",
asid:null,
needPing:true,
opener:'',
beginX:0,
beginY:0,
eventMouseDown : function (e){
cnst.beginX=e.pageX+3;
cnst.beginY=e.pageY+3;
$('#consultant_square').css({top:cnst.beginY,left:cnst.beginX,height:0,width:0,display:'none'})
return false;
},
eventMouseUp : function (e){
if(cnst.beginX>=e.pageX || cnst.beginY>=e.pageY){
$('#consultant_square').hide();
return false;
}
// alert(window.opener.currentKey)
var data={
// 'key':window.opener.consultant.currentKey,
'width':$(window).width(),
'height':$(window).height(),
'beginX':cnst.beginX,
'beginY':cnst.beginY,
'endX':e.pageX,
'endY':e.pageY,
'scrollTop':$(window).scrollTop(),
'scrollLeft':$(window).scrollLeft(),
'type':'square'
};
cnst.beginX=0;
cnst.beginY=0;
$.getJSON(SERVER_URL+'/consultant/consultant.php?act=sendCommand&callback=?'+(cnst.sid?'&CONSESSID='+cnst.sid:''),data,function(){});
},
eventMouseMove : function (e){
if(cnst.beginX+cnst.beginY){
$('#consultant_square').show().css({height:e.pageY-cnst.beginY,width:e.pageX-cnst.beginX})
return false
}
},
eventClick : function (){
var data={
'type':'click',
'message':$(this).attr('href')
};
$.getJSON(SERVER_URL+'/consultant/consultant.php?act=sendCommand&callback=?'+(cnst.sid?'&CONSESSID='+cnst.sid:''),data,function(resp){
document.location.href=data.message;
});
return false;
},
openConsultant : function (){
var width=400;
var height=560;
var screen_width = window.screen.width;
var screen_height = window.screen.height;
width += 40;
height += 30;
if(width > screen_width){
width = screen_width - 40;
}
if(height > screen_height){
height = screen_height - 100;
}
var consultant=window.open( SERVER_URL+'/consultant/?url='+document.location.href+(cnst.sid?'&CONSESSID='+cnst.sid:'') , 'windetail', 'width='+width+',height='+height+', top=20, left=20, resizable=1, scrollbars=1' );
consultant.focus();
},
closeAlert : function (){
$('#messager').css('display','none');
$('#invite').html('');
return false;
},
pingConsultant : function() {
if(!cnst.needPing){
var id=setTimeout("cnst.pingConsultant()", cnst.timer);
return;
}
$.getJSON(SERVER_URL+'/consultant/consultant.php?act=pingPage&time='+cnst.time+'&href='+document.location.href+'&callback=?'+(cnst.sid?'&CONSESSID='+cnst.sid:''),cnst._pingConsultant);
},
_pingConsultant : function(resp){
if(resp.PHPSESSID){
cnst.sid=resp.PHPSESSID;
}
if(resp.message){
var message=resp.message;
if(message.type=='invite'){
if($('#messager').css('display')=='none'){
$('#messager').animate({width: 'toggle',height: 'toggle'});
}
$(''+message.user+':
'+message.message+'
').appendTo('#invite');
// alert(message.message)
if(resp.avatar){$('#messager .m_avatar').attr('src',SERVER_URL+resp.avatar)}
}else if(message.type=='square'){
// alert();
var data=message.message;
$(window).scrollTop(data.scrollTop);
$(window).scrollLeft(data.scrollLeft);
$('#consultant_square').show().css({top:data.beginY+'px',left:data.beginX+'px',width:data.endX-data.beginX,height:data.endY-data.beginY});
var width=data.width;
var height=data.height;
resizeBy(width-$(window).width(),height-$(window).height());
}else if(message.type=='click'){
document.location.href=message.message;
return;
}
}
if(resp.time){
cnst.time=resp.time
}
if(resp.operator_online){
$("#online").removeClass('operator_status_offline').html('Консультант on-line');
}else{
$("#online").addClass('operator_status_offline').html('Оставить заявку');
}
var id=setTimeout("cnst.pingConsultant()", cnst.timer);
}
}
//Патч для эксплорера
var consultant_sid=null;
if(consultant_sid=getHref('asid')){
setCookie('CONSESSID',consultant_sid,null,'/');
setCookie('a_sid',consultant_sid,null,'/');
// alert(getHref('asid'))
}
var a_sid=null;
if(a_sid=getCookie('a_sid')){
cnst.asid=a_sid;
// alert(a_sid)
}
if(consultant_sid=getCookie('CONSESSID')){
cnst.sid=consultant_sid;
}else{
consultant_sid=cnst.sid;
setCookie('CONSESSID',cnst.sid,null,'/');
}
function getHref(name) {
var href = "" + document.location.href;
var search = "" + name + "=";
var setStr = null;
var offset = 0;
var end = 0;
if (href.length > 0) {
offset = href.indexOf(search);
if (offset != -1) {
offset += search.length;
end = href.indexOf("&", offset)
if (end == -1) {
end = href.length;
}
setStr = unescape(href.substring(offset, end));
}
}
return(setStr);
}